import { withRouter } from 'next/router';
import { destination_map } from '@/config';
import Head from '@/components/Head';
import Tkd from '@/ssr/tkd';
// css
import styles from '@/styles/Index.module.scss';
// 组件
import Recommend from '@/pages_components/home/Recommend';
import Tour from '@/pages_components/home/Tour';
import Guide from '@/pages_components/home/Guide';
import CouponPopover from '@/pages_components/home/CouponPopover';
// api
import { homePage_recommend_SSR, destinationPart_SSR, guidePart_SSR } from '@/ssr';

const Home = ({ recommend_ssr, linzhi_ssr, lasa_ssr, ali_ssr, guide_ssr }) => {
  return (
    <div className={styles["home-page"]}>
      {/* 标题/关键字/网页描述 */}
      <Head meta={Tkd['/']} />
      <div className="max-content">
        {/* 特价/今日推荐 */}
        <section className={[styles['part'], styles['recommend']].join(' ')}>
          <Recommend data={recommend_ssr} />
        </section>
        {/* 林芝旅游 */}
        <section className={[styles['part'], styles['linzhi']].join(' ')}>
          <Tour title="林芝旅游" data={linzhi_ssr} />
        </section>
        {/* 拉萨旅游 */}
        <section className={[styles['part'], styles['lasa']].join(' ')}>
          <Tour title="拉萨旅游" data={lasa_ssr} />
        </section>
        {/* 阿里旅游 */}
        <section className={[styles['part'], styles['ali']].join(' ')}>
          <Tour title="阿里旅游" data={ali_ssr} />
        </section>
        {/* 旅游攻略 */}
        <section className={[styles['part'], styles['guide']].join(' ')}>
          <Guide title="旅游攻略" data={guide_ssr} />
        </section>
      </div>
      <CouponPopover />
    </div>
  )
}

// ssr
Home.getInitialProps = async () => {
  const linzhi_id = destination_map['linzhi'],
        lasa_id = destination_map['lasa'],
        ali_id = destination_map['ali'];
  const { ssr: recommend_ssr } = await homePage_recommend_SSR();
  const { ssr: linzhi_ssr } = await destinationPart_SSR(linzhi_id);
  const { ssr: lasa_ssr } = await destinationPart_SSR(lasa_id);
  const { ssr: ali_ssr } = await destinationPart_SSR(ali_id);
  const { ssr: guide_ssr } = await guidePart_SSR({ limit: 3, offset: 1, pageSize: 5 });

  return { recommend_ssr, linzhi_ssr, lasa_ssr, ali_ssr, guide_ssr }
}

export default withRouter(Home)